#ifndef IFILEAPP_HPP
#define IFILEAPP_HPP

#include "ui_ifileapp.h"
#include "headers/ifile_server_comms.hpp"
#include "headers/upload_process.hpp"

#include <QCheckBox>
#include <QComboBox>
#include <QDebug>
#include <QtGui/QMainWindow>
#include <QMutex>
#include <QSignalMapper>

class ifileApp : public QMainWindow
{
    Q_OBJECT

public:

    ifileApp(QWidget * parent = 0);
    ~ifileApp();

    void setApiKey(QString apiKey);

private slots:

    void startUpLoad();
    void stopUpLoad();
    void fileStatus(IfileServerComms::FileStatusResponse);
    void exit();

    void addUploadFile();
    void addUploadFileList();
    void addUploadFolder();
    void tabChanged(int);

    void folderListReceived(QList<IfileServerComms::FolderDetails>);
    void fileListReceived(QList<IfileServerComms::FileDetails>);
    void tableItemChanged(const QString);

    void getAccountStats();
    void accountStatsUpdate(IfileServerComms::AccountStatsResponse);

    void appHelp();
    void aboutApp();

    void currentUploadFinished();
    void allUploadsFinsihed();

signals:

    void itemChanged(const QString &);

private:

    QString getApiKet();
    void setMaxUploadSlots(int);

    Ui::ifileAppClass ui;
    IfileServerComms * ifileServerComms;
    UploadProcess * uploadProcess;

    QStringList uploadFiles;
    QStringList uploadFolders;

    QStringList uploadTableHeaders;
    QTableWidgetItem * uploadTableItemOne;
    QTableWidgetItem * uploadTableItemTwo;
    QTableWidgetItem * uploadTableItemThree;
    QTableWidgetItem * uploadTableItemFour;

    QStringList folderTableHeaders;
    QTableWidgetItem * folderTableItemOne;
    QTableWidgetItem * folderTableItemTwo;
    QTableWidgetItem * folderTableItemThree;
    QTableWidgetItem * folderTableItemFour;
    QTableWidgetItem * folderTableItemFive;
    QTableWidgetItem * folderTableItemSix;

    QStringList fileTableHeaders;
    QTableWidgetItem * fileTableItemTwo;
    QTableWidgetItem * fileTableItemThree;
    QTableWidgetItem * fileTableItemFour;
    QTableWidgetItem * fileTableItemFive;
    QTableWidgetItem * fileTableItemSix;
    QTableWidgetItem * fileTableItemSeven;

    QString apiKey;
    QComboBox * accountFolders;
    QCheckBox * groupCheckBox;

    QStringList foldList;
    QMap<QString, QString> folderKeyMap;
    QMap<QString, QString> uploadFolderKeyMap;

    QSignalMapper * signalMapper;

    QMutex uploadLock;
    QMutex uploadFinishedLock;
    uint maxUploadSlots;
    uint freeUploadSlots;
    bool keepProcessing;


};

#endif // IFILEAPP_HPP
